<html>
<head>
    <meta charset="UTF-8">
    <title>videomodel</title>
</head>
<body>


<?php
require 'Common/ConnDB.php';
require 'Common/config.php';
class VideoModel{
    private $conn;
     function __construct(){
        //连接数据库
        $this->conn=new ConnDB(DB_TYPE,DB_HOST,DB_USER,DB_PWD,DB_DBNAME,DB_CHARSET);

     }


     function getVideoList(){
        //写sql语句

      $sql="select * from video";
      //执行sql语句得到数据
      $data=$this->conn->query($sql);

    return $data;
  }

function delVideo($vid){

    $sql="delete from video where vid=$vid";
    $result=$this->conn->query($sql);
    
    return $result;
  }



 
  function addvideo($data,$file){
//文件上传
    $arr=explode('.', $file['pic']['name']);
    $suffix=$arr[count($arr)-1];
    $newname=date("YmdHis").rand(100,999).'.'.$suffix;
    $filepath='./poster/';
    move_uploaded_file($file['pic']['tmp_name'], $filepath.$newname);
//把数据插入数据库
    $videoname=$data['videoname'];
    $typename=$data['typename']; 
    $pic=$newname;
    
    $intro=$data['intro'];
    $address=$data['address'];
    $uploaddate=date("y-m-d h:i:s",time());
    $sql="insert into video values(null,'$videoname','$typename','$pic','$intro','$uploaddate','$address')";
    echo $sql;
    $result=$this->conn->query($sql);
    return $result;

  }

    function editvideo($vid){
    $sql="select * from video where vid=$vid";
    $data=$this->conn->query($sql);
    return $data;
  }
function updatevideo($data,$file){
  $vid=$data['vid'];
  $videoname=$data['videoname'];
    $typename=$data['typename']; 
    $pic=$newname;
    
    $intro=$data['intro'];
    $address=$data['address'];
$uploaddate=date("y-m-d h:i:s",time());
     if ($file['pic']['size']==0) {
    
 $sql="update video set videoname='{$videoname}',typename='{$typename}',uploaddate='{$uploaddate}',address='{$address}',intro='{$intro}' where vid={$vid}";


echo $sql;
}
    
    else{
            //上传新头像并且根据uid更新数据
            //上传文件}
            $arr=explode('.', $file['pic']['name']);
            $suffix=$arr[count($arr)-1];
            $newname=date("YmdHis").rand(100,999).'.'.$suffix;
            $filepath='./poster/';
            move_uploaded_file($file['pic']['tmp_name'], $filepath.$newname);
            $sql="update video set vidoename='{$videoname}',typename='{$typename}',pic='{$newname}',intro='{$intro}',uploaddate='{$uploaddate}',address='{$address}'where vid={$vid}"; 
            echo $sql;
            
          }

              $result=$this->conn->query($sql);
    return $result;
        }
      }
?>

</head>
</body>


